package com.es.spring.controller;

import com.es.spring.annotation.Autowired;
import com.es.spring.annotation.Controller;
import com.es.spring.annotation.RequestMapping;
import com.es.spring.annotation.RequestParam;
import com.es.spring.service.DemoService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 二十
 * @since 2021/11/9 4:56 下午
 */
@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response, @RequestParam("name") String name) {
        String result = demoService.get(name);
        try {
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/add")
    public void add(HttpServletRequest request, HttpServletResponse response, @RequestParam("a") Integer a, @RequestParam("b") Integer b) {
        try {
            response.getWriter().write(a + " + " + b + "= " + (a + b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
